home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12163 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: beta.nedernet.nl!usenet
  2. From: jos@and.nl (Jos A. Horsmeier)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Int to Double, Pl Advise!
  5. Date: 29 Mar 1996 14:43:26 GMT
  6. Organization: AND Operations Research B.V.
  7. Message-ID: <4jgsuf$2ll@beta.nedernet.nl>
  8. References: <isa5224.544.315B647A@age2.age.uiuc.edu>
  9. NNTP-Posting-Host: klepzeiker.and.nl
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <isa5224.544.315B647A@age2.age.uiuc.edu>, isa5224@age2.age.uiuc.edu 
  15. wrote:
  16.  
  17. [ stripped, but kepped the essentials: ]
  18. |#define Ng 4
  19. |#define Nr 4
  20. |
  21. |int p0[Ng][Nr];
  22. |   
  23. |         x = x + ((double) p0[i,j]) / (double)(j*j); }
  24. |
  25. |I get the following compilation error(s) on MS C++ compiler:
  26. |error C2440: 'cast' : cannot convert from 'int [4]' to 'double '
  27.  
  28. When K&R designed the C language, one of their evil goals was
  29. to pester as many Pascalian victims as possible. These two villains 
  30. did not just decide to make the assignment token to be a simple '=', 
  31. 'cause those Pascalian rascals would manage to figure out that little 
  32. pitfall within a couple of hundred runtime errors and an occasional 
  33. compiler diagnostic; they even decided that the Pascal array notation
  34. would seem valid, sound and solid in C. And, syntactically speaking,
  35. it is; 'p0[i, j]' is perfectly legal C, but, (insert diabolical laughter
  36. here), it doesn't mean what it it looks like. You've been poo-poo'd by 
  37. a cleverly disguised neo-Babylonian-C-trap. (diabolical laughter again).
  38.  
  39. The expression 'i,j' means: evaluate 'i', discard the resulting value,
  40. and evaluate 'j' afterwards. The result of the entire expression equals
  41. the value of 'j'. You could have written 'p0[j]' here instead.
  42.  
  43. The nasty scoundrels they are, K&R _wanted_ you to write 'p0[i][j]', meaning:
  44. 'p0[i]' is an array of 'things', where each 'thing' is an array of 'Nr'
  45. ints, so p0[i][j] denotes the i-th 'thing' where 'j' indexes the
  46. int element in that 'thing' you were looking for ...
  47.  
  48. kind regards,
  49.  
  50. Jos aka jos@and.nl
  51. -- 
  52. Atnwgqkrl gy zit vgksr, ug qshiqwtzoeqs!
  53.  
  54.